package com.coldtech.circlecrash.handler;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import com.coldtech.circlecrash.CircleCrash;
import com.coldtech.circlecrash.Selection;

public class MouseHandler implements MouseListener {
	private ButtonHandler buttonHandler = null;
	private Selection selection = null;

	public MouseHandler(CircleCrash game) {
		this.buttonHandler = game.getButtonHandler();
		this.selection = game.getSelection();

		game.addMouseListener(this);
	}

	public void mouseClicked(MouseEvent e) {

	}

	public void mouseEntered(MouseEvent e) {

	}

	public void mouseExited(MouseEvent e) {

	}

	public void mousePressed(MouseEvent e) {
		if (e.getButton() == 1) {
			this.buttonHandler.press(e.getX(), e.getY());
			this.selection.startSelection(e.getX(), e.getY());
		}
	}

	public void mouseReleased(MouseEvent e) {
		if (e.getButton() == 1) {
			this.buttonHandler.release(e.getX(), e.getY());
			this.selection.stopSelection(e.getX(), e.getY());
		}
		if (e.getButton() == 3) {
			if (this.selection.isSelected()) {
				this.selection.moveSelectedTo(e.getX(), e.getY());
			}
		}
	}
}
